//package com.example.recordingpen_datacollection.Aliyun;
//
//import java.io.BufferedReader;
//import java.io.DataOutputStream;
//import java.io.InputStreamReader;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.nio.charset.StandardCharsets;
//import java.util.Scanner;
//
//public class Main {
//
//    private static final String USER_AGENT = "Java-HttpURLConnection/1.0";
//
//    public static void main(String[] args) throws Exception {
//        String urlStr = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
//        String apiKey = ("sk-fd35166024304acb9473aec3db52b059");
//        System.out.println(apiKey);
//        URL url = new URL(urlStr);
//        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//
//        connection.setRequestMethod("POST");
//        connection.setRequestProperty("Content-Type", "application/json");
//        connection.setRequestProperty("Authorization", "Bearer " + apiKey);
//        connection.setDoOutput(true);
//
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("请输入：");
//        String UserInput = scanner.nextLine();
//        String jsonInputString = String.format("{\"model\": \"qwen-plus\", \"input\": {\"messages\": [ {\"role\": \"user\", \"content\": \"%s\"}]}, \"parameters\": {\"result_format\": \"message\"}}",UserInput);
//        System.out.println(jsonInputString);
//
//        /**
//         * {
//         * 	"model": "qwen-turbo",
//         * 	"input": {
//         * 		"messages": [{
//         * 			"role": "system",
//         * 			"content": "You are a helpful assistant."
//         *                }, {
//         * 			"role": "user",
//         * 			"content": "1+1"
//         *        }]* 	},
//         * 	"parameters": {
//         * 		"result_format": "message"
//         * 	}
//         * }
//         */
//        try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
//            wr.write(jsonInputString.getBytes(StandardCharsets.UTF_8));
//            wr.flush();
//        }
//
//        StringBuilder response = new StringBuilder();
//        try (BufferedReader in = new BufferedReader(
//                new InputStreamReader(connection.getInputStream()))) {
//            String inputLine;
//            while ((inputLine = in.readLine()) != null) {
//                response.append(inputLine);
//            }
//        }
//
//        System.out.println(response);
//        /**
//         *{
//         * 	"output": {
//         * 		"choices": [{
//         * 			"finish_reason": "stop",
//         * 			"message": {
//         * 				"role": "assistant",
//         * 				"content": "1 + 1 equals 2."
//         *                        }* 		}]
//         * 	},
//         * 	"usage": {
//         * 		"total_tokens": 30,
//         * 		"output_tokens": 8,
//         * 		"input_tokens": 22
//         * 	},
//         * 	"request_id": "45c1440a-b9a3-990c-9f7a-f9ecbfc3ff24"
//         * }
//         */
//        connection.disconnect();
//    }
//}